<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">
    
    <title>${ webpageTitle }</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="rp/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
	   	
    </style>
	
  </head>
  
  <body class="body-fit">
  	
  	<div class="mini-toolbar" borderStyle="border:0;">
  		<table style="width: 100%;">
  			<tr>
  				<td style="width: 100%;">
  					<label>模块过滤：</label>
  					<input id="moduleTree" class="mini-treeselect" url="rp/system/moduleMng/getModules" multiSelect="false" 
				        textField="name" valueField="id" parentField="parentId" checkRecursive="true" 
				        showFolderCheckBox="false" expandOnLoad="true" showClose="true" oncloseclick="onCloseClick"
				        popupWidth="200" width="200" onvaluechanged="valuechanged()"/>
				    
  					<a class="mini-button" onclick="showAllWaitResources"><i class="fa fa-filter fa-lg"></i> 显示所有备选资源</a>
  					<a class="mini-button" onclick="goRescMng">进入资源管理</a>
  				</td>
  				<td style="white-space:nowrap;">
  					
  				</td>
  			</tr>
  		</table>
    	
    </div>
    
    <div style="width: 100%; height: 100%; padding: 5px;">
    	
    	<input type="hidden" id="authorityId" value="${ authorityId }"/>
    	
    	<div style="width: 380px; height: 400px; float: left;">
	    	<div style="width:100%;">
		        <div class="mini-toolbar" style="border-bottom:0;padding:3px;">
		            <span>备选资源</span>           
		        </div>
		    </div>
	    	<div id="waitAllotRescsGrid" class="mini-datagrid" style="width: 100%; height: 390px;"
		    	url="rp/system/rescMng/getWaitAllotResources" idField="id" allowResize="false" pageSize="50"
		  		allowCellSelect="true" multiSelect="true" showFilterRow="true"
		  		onrowdblclick="adds();">
		    	<div property="columns">
			        <div type="checkcolumn"></div>
			        <div name="name" field="name" width="70" headerAlign="center">
			        	资源名称
			        	<input id="nameFilter" property="filter" class="mini-textbox" style="width:100%;" emptyText="输入名称搜索"
		                    onenter="onNameFilterEnter"/>
			        </div>
			        <div name="url" field="url" headerAlign="center">
			        	URL
			        </div> 
			        <!-- <div name="moduleName" field="moduleName" visible="true" headerAlign="center">
			        	所属模块
			        </div> -->
			    </div>
		    </div>
	    </div>
	  	
	  	<div style="width: 60px; height: 120px; text-align:center; float: left; margin-top: 60px;">
  			<input type="button" value=">" title="加入" onclick="adds()" style="width:40px;"/><br />
            <input type="button" value=">>" title="全部加入" onclick="addAll()" style="width:40px;"/><br />
            <input type="button" value="&lt;&lt;" title="全部移除" onclick="removeAll()" style="width:40px;"/><br />
            <input type="button" value="&lt;" title="移除" onclick="removes()" style="width:40px;"/><br />
  		</div>
	  	
	  	
	  	<div style="width: 350px; height: 400px; float: left;">
	  		<div style="width:100%;">
		        <div class="mini-toolbar" style="border-bottom:0;padding:3px;">
		            <span>已选资源</span>           
		        </div>
		    </div>
	  		<div id="hasRescsGrid" class="mini-datagrid" style="width: 100%; height: 390px;"
		    	url="rp/system/rescMng/getHasResources?authorityId=${ authorityId }" idField="id" allowResize="false"
		  		allowCellSelect="true" multiSelect="true" showPager="false"
		  		onrowdblclick="removes();">
			    <div property="columns">
			    	<div type="indexcolumn" headerAlign="center">序号</div>
			        <div type="checkcolumn"></div>
			        <div name="name" field="name" width="70" headerAlign="center">
			        	资源名称
			        </div>
			        <div name="url" field="url" headerAlign="center">
			        	URL
			        </div> 
			        <!-- <div name="moduleName" field="moduleName" visible="true" headerAlign="center">
			        	所属模块
			        </div> -->
			    </div>
			</div>
	  	</div>
	  	
		
    </div>
    
    
  	
  	<div class="mini-toolbar" style="width: 100%; padding: 5px; position: fixed; bottom: 0px;" borderStyle="border:0;">
        <a class="mini-button" style="width:60px;" onclick="onOk()"><i class="fa fa-check fa-lg"></i> 确定</a>
        
        <a class="mini-button" style="width:60px;" onclick="onCancel()"><i class="fa fa-times fa-lg"></i> 取消</a>
    </div>
  	
	<script type="text/javascript">
		var waitAllotRescsGrid;
		var hasRescsGrid;	
	
		$(function(){
			mini.parse();
			waitAllotRescsGrid = mini.get("waitAllotRescsGrid");
			hasRescsGrid = mini.get("hasRescsGrid");
			hasRescsGrid.load();
		});
		
		function onCloseClick(e) {
            var obj = e.sender;
            obj.setText("");
            obj.setValue("");
        }
		
		function getValue() {
            var obj = mini.get("moduleTree");
            return obj.getValue();
        }
		
		function valuechanged(){
			waitAllotRescsGrid.load({moduleId: getValue(), authorityId: $("#authorityId").val()});
		}
		
		function showAllWaitResources(){
			mini.get("moduleTree").setValue("所有");
			waitAllotRescsGrid.load({authorityId: $("#authorityId").val()});
		}
		
		//获取选中的数据
		function getSelectData() {
	        var rows = hasRescsGrid.data;
	        return rows;
	    }
		
		function onNameFilterEnter(e) {
            var namebox = mini.get("nameFilter");
            var name = namebox.getValue().toLowerCase();
            
          	//多条件组合过滤
            waitAllotRescsGrid.filter(function(row){
                var r1 = true;
                if(name){
                    r1 = String(row.name).toLowerCase().indexOf(name) != -1;
                }
                return r1;
            });
        }
		
		function goRescMng(){
			closeWindow("cancel");
			window.parent.addMainTab("资源管理-来自分配资源页面", "rp/system/rescMng/showRescGrid");
		}
		
		//////////////////////////////////
		
		function adds() {
            var items = waitAllotRescsGrid.getSelecteds();
            waitAllotRescsGrid.removeRows(items);
            hasRescsGrid.addRows(items);
        }
        function addAll() {
            var items = waitAllotRescsGrid.getData();       
            waitAllotRescsGrid.removeRows(items);
            hasRescsGrid.addRows(items);
        }
        function removes() {
            var items = hasRescsGrid.getSelecteds();
            hasRescsGrid.removeRows(items);
            waitAllotRescsGrid.addRows(items);
        }
        function removeAll() {
            var items = hasRescsGrid.getData();
            hasRescsGrid.removeRows(items);
            waitAllotRescsGrid.addRows(items);
        }
        
        function tt(){
        	adds();
        }
		
		//////////////////////////////////
	    function closeWindow(action) {
	        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
	        else window.close();
	    }

	    function onOk() {
	    	closeWindow("ok");
	    }
	    function onCancel() {
	    	closeWindow("cancel");
	    }
	</script>
  </body>
</html>
